const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');

module.exports = merge(common, {
  optimization: {
    minimize: true,
    minimizer: [
      // we specify a custom UglifyJsPlugin here to get source maps in production
      new TerserPlugin({
        parallel: true,
        extractComments: false,
        // sourceMap: true,
        // cache: true,
        minify: TerserPlugin.terserMinify,
        terserOptions: {
          format: {
            comments: false,
          },
          compress: {
            // drop_console: true,
            pure_funcs: ['console.log', 'console.warn'],
          },
        },
      }),
      new CssMinimizerPlugin({}),
    ],
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: 'static/css/[name].bundle.[fullhash].css',
      chunkFilename: 'static/css/[name].bundle.[chunkhash].css',
    }),
    new CompressionPlugin({
      filename: '[path][base].gz',
      algorithm: 'gzip',
      test: /\.js$|\.css$|\.html$/,
      threshold: 10240,
      minRatio: 0.8,
    }),
  ],
  mode: 'production',
});
